Arduino Trolley Tutorial--fourth day (sensor)

Source: Internet
Author: User

Hello everyone, I'm a small-story.

Remember the previous section click the Open link

Today we talk about sensors.

Today, we talk about light and ultrasound.

Send a picture first:


The light sense has three interfaces, namely:

UCC, out, GND.

The ultrasound has four interfaces, namely:

UCC, T, E, GND.

Here's how it works.


The ultrasonic wave is an ultrasonic wave, the sound wave touches the object bounces, the other end receives, thus judging the distance.

Light sense is the detection of light values, judging the minimum 0 maximum 255.

Attached procedure:

Car for avoiding obstacles

#include <servo.h> int pinlf=14;     int pinlb=15;     int pinrf=16;    int pinrb=17;   int pwmen1=3;int pwmen2=5;void Setup ()  {  serial.begin (9600);      Pinmode (pinlb , OUTPUT);   Pinmode (pinlf,output);   Pinmode (pinrb,output);   PinMode (PinRF,OUTPUT) ;   Pinmode (pwmen1,output);   Pinmode (pwmen2,output);   }void advance (int a)         {     digitalwrite (pinrf,high);      digitalwrite (PINRB , low);             analogwrite (pinrf,150);            &NB Sp;analogwrite (PINRB, 0);     digitalwrite (pinlf,high);      digitalwrite (PinLB, Low);             analogwrite (pinlf,150);            &NBS P;analogwrite (pinlb,0);     deLay (A * 100);        }void right (int b)            {    &NBSP;DIGITALW Rite (Pinrf,low);     digitalwrite (Pinrb,low);                analogwrite (pinrf,0);          &NBSP ;  analogwrite (PINRB, 0);     digitalwrite (Pinlf,high);        digitalwrite (pinlb,low);             analogwrite ( pinlf,150);             analogwrite (pinlb,0);     delay (b * 100);    }void left (int c)             {     digitalwrite (pinrf,hig H);     digitalwrite (Pinrb,low);                analogwrite (pinrf,150);          &NB Sp  analogwrite (PINRB, 0);     digitalwrite (Pinlf,low);        digitalwrite (pinlb,low);             analogwrite (pinlf,0);              analogwrite (pinlb,0);     delay (c * +);   }voi d turnr (int d)            {     digitalwrite (pinrf,low);     d Igitalwrite (Pinrb,high);                analogwrite (pinrf,0);          &NBSP ;  analogwrite (PINRB);     digitalwrite (Pinlf,high);        digitalwrite (pinlb,low);             analogwrite ( pinlf,100);             analogwrite (pinlb,0);     delay (d * 100);    }void turnl (int e)            {     digitalwrite (pinrf,high); &n Bsp    digitalwrite (Pinrb,low);                analogwrite (pinrf,150);            &NBSP;ANALOGWRI Te (PINRB, 0);     digitalwrite (Pinlf,low);        digitalwrite (pinlb,high);             analogwrite ( pinlf,0);             analogwrite (pinlb,150);     delay (E * 100);        void Stopp (int f)             {     digital Write (pinrb,low);     digitalwrite (pinrf,low);     digitalwrite (pinlb,low);     digitalwrite (pinlf,low);     delay (f * +);   }void back (int g)     &nbs P     {     digitalwrite (pinrf,low)       digitalwrite (Pinrb,high);              analogwrite (pinrf,0);            &NBsp;analogwrite (PINRB);     digitalwrite (Pinlf,low);       digitalwrite (pinlb,high);             analogwrite (pinlf,0 );             analogwrite (pinlb,150);     delay (g * 100);        }void loop ()  {    Advance (1)             &N bsp;    Delay (; )   back (1);                     delay (1000);        TURNL (1);                   delay (1000);        TURNR (1);                         delay (&NBSP);

Tracking trolley

#include <Servo.h> int pinlf=14;     int pinlb=15;     int pinrf=16;   int pinrb=17;    int pwm1=3;   int pwm2=5;  void Setup () {  serial.begin (9600);      Pinmode (pinlb,output);   Pinmode (pinlf,output);   Pinmode (pinrb,output);   Pinmode (pinrf,output);    } void advance (int a)       {     digitalwrite (pinrf,high);       Digitalwrite (pinrb,low);             Analogwrite (pinrf,130);             Analogwrite (PINRB, 0);     Digitalwrite (Pinlf,high);      Digitalwrite (pinlb,low);             Analogwrite (pinlf,200);             Analogwrite (pinlb,0);     Delay (A *);         } void Loop () {    advance (1);                }


Thank you

Arduino Trolley Tutorial--fourth day (sensor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.