int DO = 6; //Pin for Digital Output - DO
int DA = A0; // Pin for Analog Output - AO
int threshold = 12; //Set minimum threshold for LED lit
int sensorvalue = 0;
int duration = 11;
int trig = 12;
#include <Servo.h>
Servo lock; // create servo object to control a servo
Servo gate; // a maximum of eight servo objects can be created
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
lock.attach(6); // attaches the servo on pin 9 to the servo object
gate.attach(8);
Serial.begin(9600);
pinMode(12, OUTPUT);
pinMode(11, INPUT);
}
void loop()
{
sensorvalue = analogRead(DA); //Read the analog value
Serial.print("Analog: ");
Serial.print(sensorvalue); //Print the analog value
Serial.print(" ");
Serial.print("Digital: ");
Serial.println(digitalRead(DO)); //Print the digital value
if (sensorvalue >= threshold){ //Compare analog value with threshold
lock.write(0); //unlocked angle
delay(1500);
gate.write(90); //open angle
delay(10000);
This is my project. the point of this is that if the decibels are above 12, the servo will unlock, and if less than 17 inches on an ping))) then it will not open. It keeps on saying that inches are not declared. Please help me with this since i dont want to fail. Preferably give me instructions on what to do for my whole project (i only have 3 left)
pbjmaster:
by fail i mean fail a high school class
Keep in mind that you are one who may or may not fail as such you should do what others have asked of you instead of ignoring them. You need to do something to pass the course we do not.
Look up what it means to declare a variable in C, Google is your friend.
im building a baby gate in class. The idea is that a clap or snap that is higher than 20 decibels will turn it on. But if there is something in front of the ultrasonic sensor within 20 inches, the gate will not open. There is one servo to open/lock our lock, and one to open/close the gate. The sensors wont work, so can someone tell me how to fix my code.?
int threshold = 13; //Set minimum threshold for LED lit
int sensorvalue = 0;
long duration, inches;
#include <Servo.h>
Servo lock; // create servo object to control a servo
Servo gate; // a maximum of eight servo objects can be created
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
lock.attach(6); // attaches the servo on pin 9 to the servo object
gate.attach(8);
pinMode(12, OUTPUT);
pinMode(11, INPUT);
}
void loop()
{
gate.write(90); // alosed and locked angles
lock.write(90);
sensorvalue = analogRead(A0); //Read the analog value
Serial.print("Analog: ");
Serial.println(sensorvalue); //Print the analog value //Serial.print(" "); //Serial.print("Digital: "); //Serial.println(digitalRead(DO)); //Print the digital value
digitalWrite(12, LOW);
delayMicroseconds(2);
digitalWrite(12, HIGH);
delayMicroseconds(5);
digitalWrite(12, LOW);
duration = pulseIn(11, HIGH); // measure the time of flight of sound wave
inches = duration / 74 / 2; // 1130 ft/s * 12in/ft * 1s/1,000,000us = 74 // factor of 2 since sound travels out and back
Serial.print(inches);
Serial.println(" inches");
The sensors wont work, so can someone tell me how to fix my code.?
Perhaps the mysterious sensors just need a good motivational speech. If you expect us to help, you need to tell us something about the sensors, AND show your serial output.
I don't think I've ever seen a servo attached to the smiley face pin. Perhaps that pin doesn't support a servo.