/*----------------------------------------------------------------- * Serial communication with the Arduino * (Like, for example - receiving data from Raspberry Pi) * Setup: Wire a servo motor to +5v, Gnd and pin 6 -----------------------------------------------------------------*/ #include char inData; // variable for storing received serial data int convertData; // variable or storing data converted into integers int ledPin = 13; // variable for LED pin number int servoPin = 6; // variable for servo pin number Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards void setup(){ Serial.begin(9600); pinMode(ledPin, OUTPUT); // set pin Mode for lighting LED myservo.attach(servoPin); // attaches the servo on pin 6 to the servo object } void loop(){ if (Serial.available() > 0){ // if serial data (RPi to Arduino) inData = Serial.read(); // read it, store in inData delay(15); convertData = (int)inData - 48; // Convert char into an integer Serial.println(convertData); // print it in the serial monitor if(convertData == 0) { // If data is a "0" digitalWrite(ledPin, HIGH); // LED "on" myservo.write(180); // tell servo to go to position 180 delay(10); // delay to read LCD characters } else { digitalWrite(ledPin, LOW); // LED "off" myservo.write(10); // tell servo to go to position 0 delay(10); // delay to read LCD characters } } }