Ans 9)
const int lightPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(lightPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
int sensorValue = analogRead(ldrPin);
if (sensorValue <= 200) {
digitalWrite(lightPin, HIGH);
Serial.print("Turn lights ON");
} else {
digitalWrite(lightPin, LOW);
Serial.print("Turn Lights OFF");
}
}
Ans 10) To detect obstacle and stop car, ultrasonic sensor is more suitable as it can work in both day and night conditions. You can also measure distance of obstacle with this sensor and stop the car accordingly. Depending on the preset distance you can disable the motors of the car to stop them completely. The code for using ultrasonic sensor shown below turns on the buzzer when obstacle is within the preset distance:
int trigger_pin = 2; int echo_pin = 3; int buzzer_pin = 10; int time; int distance; int sensorValue; void setup ( ) { Serial.begin (9600); pinMode (trigger_pin, OUTPUT); pinMode (echo_pin, INPUT); pinMode (buzzer_pin, OUTPUT); } void loop ( ) { digitalWrite (trigger_pin, HIGH); delayMicroseconds (10); digitalWrite (trigger_pin, LOW); time = pulseIn (echo_pin, HIGH); sensorValue = (time * 0.034) / 2; distance = sensorValue; if (distance <= 10) { Serial.println ("StopTheCar"); Serial.print (" Distance= "); Serial.println (distance); digitalWrite (buzzer_pin, HIGH); delay (500); } else { Serial.println (" Safe to drive "); Serial.print (" Distance= "); Serial.println (distance); digitalWrite (buzzer_pin, LOW); delay (500); } }
Note. You can disable the car motors to stop it by inserting the code same as above code for controlling buzzer, because car circuit details are not given. Also go through the use of ultrasonic sensor and it's pin configurations.
12) You can use following command to set 9600 baud rate.
void setup ( ) { Serial.begin (9600);
}
9. Consider a light sensor that is in a "Smart Car". The light sensor is used...
I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...
The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have been placed above a conveyer belt to enables parts on the belt to be photographed and analyzed. You are to augment the system that has been put in place by writing C code to detect the number of parts on the belt, and the positions of each object. The process by which you will do this is called Connected Component Labeling (CCL). These positions...