Pages: [1] 2   Go Down
Author Topic: New with sensors  (Read 1327 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I really need your help.

Basically I have this Sharp sensor

http://docs-europe.electrocomponents.com/webdocs/0a71/0900766b80a71447.pdf

and what I need it to do is when it detects any movement, trigger a fan for 5 seconds

then sensor is on pin 0 and the fan is on pin 13


Please help.

Thanks
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That sensor has an analogue output so you have to run it into one of the analogue pins, not pin 0.

Then read the value with analogRead(), decide if the value is different to the last reading and if so start the fan and also start a timer. After 5 seconds stop the fan.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Thanks for getting back to me.

Okay so how would I go about programming that?


int sensorPin = A0;    //sensonr
int fanPin = 13;      // fan
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(fanPin, OUTPUT); 
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on
  digitalWrite(fanPin, HIGH); 
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);         
  // turn the ledPin off:       
  digitalWrite(fanPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);                 
}
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What you have there is a lot different to the problem stated in the OP.

If you want the LED to flash at different speeds according the the value read from the sensor that yes that looks good.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

erm no hahha

I just want it to go on for 5 secs when the sensor picks something up,


so far nothing is happening smiley-sad  at all
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So what's with the code? Just print the values you're getting from the sensor to the serial monitor to get an idea of what's happening.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how do I do that?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when I do it, it just keeps coming up with 0
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Post the actual code you are using and a schematic or description of the circuit you have.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1058
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


int sensorValue = 0;

The sensorvalue could be between 0 and 1023, so you should use

unsigned long sensorValue = 0;

and your test for starting the fan somthing like

if (sensorValue >500){

digitalWrite(fanPin, HIGH);
delay(5000);
digitalWrite(fanPin, LOW);


}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

int sensorPin = A0;    // select the input pin for the ir sensor
int fanPin = 13;      // select the pin for the fan
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(fanPin, OUTPUT); 
}


void loop() {

             
if (sensorValue >500)

digitalWrite(fanPin, HIGH);
delay(5000);
digitalWrite(fanPin, LOW);
}
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That code doesn't print anything, refer to reply #8.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey, yea sorry,

I managed to get it printing now,


now im trying to get this to trigger the thing for light/fan  for 5 seconds when it senses anything
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well when you get the urge to share some data we'll be here smiley

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that was the code I used to get it to read the IR pin


int IRpin = 0;                                    // analog pin for reading the IR sensor
void setup() {
  Serial.begin(9600);                             // start the serial port
}
void loop() {
  float volts = analogRead(IRpin)*0.0048828125;   // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
  float distance = 65*pow(volts, -1.10);          // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
  Serial.println(distance);                       // print the distance
  delay(100);                                     // arbitary wait time.
}
Logged

Pages: [1] 2   Go Up
Jump to: