Arduino Code for relay
Turns given PIN (exmaple 12) on for a third of a second when receiving any input through serial connection
Recommend not using PIN13 due to signals being sent to it durning startup
To send signal to Arduino from computer (Linux):
echo '1' > /dev/ttyUSB0 #as root
Created By
Kris Occhipinti
June 19th, 2015
http://www.filmsbykris.com
License GPLv3
http://www.gnu.org/licenses/gpl-3.0.txt
Solution:
int inByte = 0;
int led = 12;
void setup()
{
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
pinMode(led, OUTPUT);
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
inByte = Serial.read();
// if we get a valid byte, read analog ins:
if (inByte != -1) {
Serial.println(inByte);
digitalWrite(led, HIGH);
delay(300);
}else{
digitalWrite(led, LOW);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("waiting..."); // send an initial string
digitalWrite(led, LOW); //switch off
delay(300);
}
}
C Program Quadratic equation
Learn More :
Arduino
- C Program to Demonstrates changing the keypad size and key values.
- C Program Turns on an LED on for one second, then off for one second, repeatedly
- C Program Duino Starter nRF24L01 Transmit JoyStick
- C Program : 4x4 Matrix Keypad connected to Arduino. This code prints the key pressed on the keypad to the serial port.
- Programa C para controlar una matriz de 8x8 de LEDs para mostrar una serie de 0-9
- Arduino Intro C Program
- C Program to Arduino rest [Mac/IP del shield]
Relay