Day 3:
[embedpress]https://docs.google.com/presentation/d/e/2PACX-1vTxBjotQs1qYZ46zXqki7yKJmdcEeLJ3wfVdr6TUSL8aycan-kL4uNeIUokYsNv2_R88lwPQCBzcobl/pub?start=false&loop=false&delayms=60000[/embedpress]
You can download the slide from here: https://docs.google.com/presentation/d/1kqk4nog8GBOSvketDq7LDDCei3aIsIBOnSM-j6qu0wY/edit?usp=sharing
IR Sensor Module:
int ledPin = 13; void setup() { // put your setup code here, to run once: pinMode(A0,INPUT); pinMode(ledPin,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: //Serial.println(analogRead(A0)); //delay(1000); if(analogRead(A0) < 250) digitalWrite(ledPin,HIGH); else digitalWrite(ledPin,LOW); }
Servo Module:
// Include the Servo library #include <Servo.h> // Declare the Servo pin int servoPin = 3; // Create a servo object Servo Servo1; void setup() { // We need to attach the servo to the used pin number Servo1.attach(servoPin); } void loop(){ // Make servo go to 0 degrees Servo1.write(0); delay(1000); // Make servo go to 90 degrees Servo1.write(90); delay(1000); // Make servo go to 180 degrees Servo1.write(180); delay(1000); }
L298N Code:
int motor1pin1 = 2; int motor1pin2 = 3; int motor2pin1 = 4; int motor2pin2 = 5; void setup() { // put your setup code here, to run once: pinMode(motor1pin1, OUTPUT); pinMode(motor1pin2, OUTPUT); pinMode(motor2pin1, OUTPUT); pinMode(motor2pin2, OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(motor1pin1, HIGH); digitalWrite(motor1pin2, LOW); digitalWrite(motor2pin1, HIGH); digitalWrite(motor2pin2, LOW); delay(1000); digitalWrite(motor1pin1, LOW); digitalWrite(motor1pin2, HIGH); digitalWrite(motor2pin1, LOW); digitalWrite(motor2pin2, HIGH); delay(1000); }