Easy-Connect-Software-Outline

From ArduinoInfo
Revision as of 22:03, 7 March 2019 by TerryKing (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

V2.21 2/28/2019 Questions: terry@yourduino.com

NOTE: UNDER CONSTRUCTION - This is not Student-useable at this time

Introduction

  • WHAT IT DOES: Provides several preprogrammed Examples for users
  • Uses the KEYES Easy-Plug board V2.0
  • SEE the comments after "//" on each line below
  • CONNECTIONS: KEYES Easy-plug Control board V2.0
  • NOTE: See updated connections in the Easy-plug Education software. Many pins are re-used in different projects.


There are a series of "Examples" that cover different concepts in Physical Computing, like Sensors, Actuators, Decision Making, Communications etc..

INITIAL SETUP:

  • User connects LCD display to I2C connector
  • User connects IR Receiver module to connector D5
  • User connects USB cable or battery pack to Easy-Plug control board

USER SELECTION OF EXAMPLES:

  • User uses the number buttons on the IR remote to select different examples
  • User must press RESET button to select a new example

/*-------------( Example 0: DIGITAL OUTPUT )--[Power-On DEFAULT]-------

This is the default example running at power-on or reset

  • Blinks Morse Code "HI" on pins 6, 7 and 13.
  • User sees blink on onboard LED pin 13.
  • User connects buzzer brick to STROBE_LED_PIN (7) so Morse is audible
  • Morse is discussed. Digital is discussed. Look at cables and colors.
  • User uses a cable to connect bright LED brick to pin 7

/*-------------( Example 1: DIGITAL INPUTS )---------------

  • Bright LED connected to LED_MODULE_PIN: D6 lights when switch is ON.
  • Buzzer connected to D7
  • User connects various different switches to A3
  • User pushes button brick, ON-OFF, TRUE-FALSE, 1-0, HIGH-LOW discussed.
  • LCD displays “IT’S OFF! 0 LOW” or “IT’S ON! 1 HIGH
  • Other bricks are connected to pin A3: Tilt, maybe others
  • Bare wires connected to pin A3; conductors/insulators discussed.
  • Motion Detect (Active Low) is connected to A3. D8 is shown to “Fix it in Software”

/*-----------------( Example 2: Analog to LCD )-------------

  • Potentiometer connected to A0
  • Photoresistor connected to A1
  • Compare light level, turn on LED light if dark
  • Voltage dividers discussed?
  • Different resistive type sensors discussed
  • LCD Displays the values of knob and Photoresistor (0..1024)  ?Discuss binary?

/*------------------( Example 3: Analog IN / OUT )----------------

  • Analog variable from user's Potentiometer on A0
  • Dimming of Bright LED on LED_MODULE Pin 6
  • Strobe blink speed on STROBE LED on Pin 9
  • + BUZZER if "TooFast"
  • Servo Position on pin A2 (Speedometer)
  • Possible "Dashboard" construction: "Make A New Device"

/*------------------( Example 4: Temperature and Humidity with DHT11 Sensor )----------------

  • User connect DHT11 sensor to D8
  • LCD Displays Temperature / Humidity
  •  ? What If - the user want to be able to see temperature in both C and F ?
  • User plugs in a Switch which changes display from Centigrade to Fahrenheit

/*------------------( Example 5: Test handheld IR Remote: display codes )----------------

  • User selects "5" with IR remote
  • User presses all the different buttons on the remote, sees results
  • User aligns the IR receiver with the remote and backs off to determine range.
  •  ? What is Infrared light? Can we see it on a digital camera / Phone?? (Iphone user-facing camera)
  •  ? How does the handheld communicate? (Need graphic )

/*--------------------( Example 6: Test Ultrasonic Sensor module )---------------------------

  • User connects the Ultrasonic Sensor Module to connector D3D4
  • User aims the sensor to an open area
  • User Places different objects in front of the sensor, sees distance displayed on LCD
  • User connects Buzzer to D7, hears beep speed change with distance.
  •  ? How could this be used by a blind person ?

/*--------------------( Example 7: Test Joystick )---------------------------

  • User connects the Joystick D2A6A7
  • User Moves the Joystick over X-Y area
  • User sees the X and Y values displayed on the LCD display
  • User pushes DOWN on joystick, sees "Z" value (Zero or One) displayed, LED13 goes ON and OFF

/*--------------------( Example 8: System for Traffic System )---------------------------

CONNECTIONS:

  • Ultrasonic Sensor Module to D3D4
  • Touch switch to A0
  • RED LED Module to D6
  • YELLOW LED Module to D7
  • GREEN LED Module to D8
  • WHITE LED Module to D9
  • User arranges LEDs as a traffic signal RED-YELLOW-GREEN
  • User arranges WHITE LED as WALK signal
  • User makes a model intersection with the traffic signal, with the Ultrasonic sensor detecting approaching vehicle on side street, and with a WALK button at the main street.
  • The system runs the traffic signal sequence and timing. It responds to a vehicle on the cross street, and to the Walk button being pressed.
  • The development of a system like this is discussed. The State Machine that controls the system is discussed and diagrammed.

CODE for this example

SORRY THIS DOESN'T WORK FORMATTING TO BE UPDATED. GGrrr.. /* YourSmartDuino-EM TRAFFIC SIGNAL: Example 8

 - WHAT IT DOES: ***
 - Uses the KEYES Easy-Plug Modules
 - V3. 2/18/2019
  Questions: terry@yourduino.com
 - SEE the comments after "//" on each line below
 - CONNECTIONS: KEYES Easy-Plug Control Board V2.0
   NOTE: Different Software examples use a different sets of modules.


 /*-----( Import needed libraries )-----*/

// Get the LCD I2C Library here: // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

  1. include <LiquidCrystal_I2C.h>

/*----------------( Declare Constants and Pin Numbers )-------------------*/ //----( DIGITAL Pins)----

//----- ( 2 pins in socket labelled D3 D4 can be used for Ultrasonic )-----

  1. define ULTRA_TRIG_PIN 3 // Connect to socket labelled "D3D4
  2. define ULTRA_ECHO_PIN 4
  3. define BUZZER_PIN 5
  4. define RED_LIGHT 6 // Traffic Lights for specific example
  5. define YELLOW_LIGHT 7
  6. define GREEN_LIGHT 8
  7. define WALK_LIGHT 9
  1. define ONBOARD_LED_PIN 13

//----( DIGITAL INPUT Pins)----

  1. define REQUEST_WALK_PIN A0 // Digital request traffic wal
  2. define SWITCH_PIN A3 // Used for a variety of On-OFF Devices


//------( LOCAL DEFINITIONS )---------

  1. define ON 1
  2. define OFF 0
  1. define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters).
  2. define US_ROUNDTRIP_CM 58.2 // Ultrasonic Sensor constant

//-----( Traffic Control System States and definitions )-------

  1. define GREEN_STATE 0
  2. define CAUTION_STATE 1
  3. define RED_STATE 2
  4. define WALKING_STATE 3
  5. define WALK_FAST_STATE 4
  1. define MaxGreenSeconds 20
  2. define MinGreenSeconds 10
  3. define YellowSeconds 5
  4. define MaxRedSeconds 10
  5. define VehicleCloseCm 10 // Vehicle in sidestreet at light

/*--------------------( Declare objects )-------------------------*/ LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Define the LCD Display


/*------------------------( Declare Variables )-----------------------------------*/ //*** boolean ShowedON = false; boolean ShowedOFF = false;

int TrafficControlState = 0; // ---( For Traffic Light Control example )---- int StateDelaySeconds; // Variable set for Traffic Light sequence states boolean VehicleDetected = false; //Set by Ultrasonic Distance Sensor boolean TrafficSenseCall = false; boolean WalkerSenseCall = false;

long duration_uS; // Duration used to calculate distance by Ultrasonic Sensor int DistCM; // Measured distance in CM

void setup() /******************* SETUP: RUNS ONCE *************************/ {

 Serial.begin(115200);        // Start up the Serial Monitor
 lcd.begin(16, 2);  // initialize the lcd for 16 chars 2 lines, turn on backlight
 lcd.noBacklight();
 delay(500);
 lcd.backlight(); // finish with backlight on
 lcd.setCursor(0, 0); //Start at character 0 on line 0
 lcd.print(F("EasyConnect By"));
 lcd.setCursor(0, 1); //Start at character 0 on line 0
 lcd.print(F("YourDuino.com"));
 //
 pinMode(ULTRA_TRIG_PIN, OUTPUT);
 pinMode(ULTRA_ECHO_PIN, INPUT);
 pinMode(BUZZER_PIN, OUTPUT);
 pinMode(REQUEST_WALK_PIN, INPUT_PULLUP);
 pinMode(GREEN_LIGHT, OUTPUT);
 pinMode(YELLOW_LIGHT, OUTPUT);
 pinMode(RED_LIGHT, OUTPUT);
 pinMode(WALK_LIGHT, OUTPUT);
 Serial.println("Option 18: TRAFFIC SIGNAL");
 lcd.setCursor(0, 0); //Start at character 0 on line 0
 //-----------1234567890123456----------
 lcd.print(F("8:TRAFFIC LIGHT "));
 StateDelaySeconds = MaxGreenSeconds;
 TrafficSenseCall = false;
 WalkerSenseCall = false;
 delay(2000);

}//--(end setup )---


void loop() /********************** LOOP: RUNS CONSTANTLY ************************/ {

 lcd.setCursor(0, 1); //Start at character 0 on line
 //-------------------1234567890123456----------
 lcd.print(F("                "));
 lcd.setCursor(0, 1); //Start at character 0 on line
 lcd.print(F("STATE="));
 lcd.print(TrafficControlState);
 delay(100);


 if (SideStreetVehicleSense() == true)
 {
   TrafficSenseCall = true;
 }
 if (digitalRead(REQUEST_WALK_PIN) == 0)
 {
   WalkerSenseCall = true;
 }


 switch (TrafficControlState)
 {
   case GREEN_STATE:
     {
       Serial.println("GREEN");
       lcd.setCursor(8, 1); //Start at character 9 on line
       lcd.print(F("GREEN"));
       digitalWrite(GREEN_LIGHT, ON);
       digitalWrite(RED_LIGHT, OFF);
       if (StateDelaySeconds >= 0)
       {
         lcd.setCursor(14, 1); //Start at character 14 on line
         lcd.print(StateDelaySeconds);
         delay(1000);
         Serial.println(StateDelaySeconds);
         StateDelaySeconds -= 1;
       }
       else
       {
         StateDelaySeconds = YellowSeconds;
         TrafficControlState = CAUTION_STATE;
       }
       if (  (TrafficSenseCall | WalkerSenseCall)
             & (StateDelaySeconds < MinGreenSeconds) )
       {
         Serial.println("Vehicle/Walker Sensed");
         TrafficSenseCall = false;
         StateDelaySeconds = YellowSeconds;
         TrafficControlState = CAUTION_STATE;
       }
     }//End GREEN_STATE
     break;
   case CAUTION_STATE:
     {
       Serial.println("YELLOW");
       lcd.setCursor(8, 1); //Start at character 9 on line
       lcd.print(F("YELLOW"));
       digitalWrite(GREEN_LIGHT, OFF);
       digitalWrite(YELLOW_LIGHT, ON);
       if (StateDelaySeconds >= 0)
       {
         lcd.setCursor(15, 1); //Start at character 14 on line
         lcd.print(StateDelaySeconds);
         delay(1000);
         Serial.println(StateDelaySeconds);
         StateDelaySeconds -= 1;
       }
       else
       {
         StateDelaySeconds = MaxRedSeconds;
         TrafficControlState = RED_STATE;
       }
       TrafficSenseCall = false;
     }//End CAUTION_STATE
     break;
   case RED_STATE:
     {
       Serial.println("RED");
       lcd.setCursor(8, 1); //Start at character 9 on line
       lcd.print(F("RED"));
       digitalWrite(RED_LIGHT, ON);
       digitalWrite(YELLOW_LIGHT, OFF);
       if (StateDelaySeconds >= 0)
       {
         delay(1000);
         Serial.println(StateDelaySeconds);
         StateDelaySeconds -= 1;
       }
       else
       {
         StateDelaySeconds = MaxGreenSeconds;
         TrafficControlState = GREEN_STATE;
       }
       if (WalkerSenseCall)
       {
         Serial.println("Walker Sensed");
         WalkerSenseCall = false;
         TrafficControlState = WALKING_STATE;
       }
     }
     break;


   case WALKING_STATE:
     {
       Serial.println("WALKING");
       lcd.setCursor(8, 1); //Start at character 9 on line
       lcd.print(F("WALKING"));
       digitalWrite(BUZZER_PIN, ON);
       delay(100);
       digitalWrite(BUZZER_PIN, OFF);
       delay(100);
       digitalWrite(BUZZER_PIN, ON);
       delay(100);
       digitalWrite(BUZZER_PIN, OFF);        
       delay(700);
       digitalWrite(WALK_LIGHT, ON);
       delay(5000);
       digitalWrite(WALK_LIGHT, OFF);
       StateDelaySeconds = 4;
       TrafficControlState = WALK_FAST_STATE;
     }
     break;
   case WALK_FAST_STATE:
     {
       Serial.println("WALK FAST");
       lcd.setCursor(8, 1); //Start at character 9 on line
       lcd.print(F("RUN ! !"));
       if (StateDelaySeconds >= 0)
       {
         delay(500);
         digitalWrite(WALK_LIGHT, ON);
         digitalWrite(BUZZER_PIN, ON);
         delay(500);
         digitalWrite(WALK_LIGHT, OFF);
         digitalWrite(BUZZER_PIN, OFF);
         Serial.println(StateDelaySeconds);
         StateDelaySeconds -= 1;
       }
       else
       {
         delay(2000);
         StateDelaySeconds = MaxGreenSeconds;
         TrafficControlState = GREEN_STATE;
         WalkerSenseCall = false;
       }
     }
     break;


     delay(500);
 } //End Switch on TrafficControlState


}//--(end main loop )---


/*--------------------( Declare User-written Functions )------------------------*/ boolean SideStreetVehicleSense() {

 /* The following trigPin/echoPin cycle is used to determine the
   distance of the nearest object by bouncing soundwaves off of it. */
 digitalWrite(ULTRA_TRIG_PIN, LOW);  // Pulse the Trigger  pin High and then Low
 delayMicroseconds(2);
 digitalWrite(ULTRA_TRIG_PIN, HIGH);
 delayMicroseconds(10);
 digitalWrite(ULTRA_TRIG_PIN, LOW);
 duration_uS = pulseIn(ULTRA_ECHO_PIN, HIGH);
 //Calculate the distance (in cm) based on the speed of sound.
 DistCM = duration_uS / US_ROUNDTRIP_CM; // Calculate distance in CM
 Serial.print("DistCM = ");
 Serial.println(DistCM);
 if (DistCM <= VehicleCloseCm)
   return true;
 else
   return false;

}// END CheckSideStreet


//*********( THE END )***********
</nowiki>