wally
Created November 30, 2018 © MIT

AI enV-Protector: Spots, Prevents, and Reports Polluters.

A motorized AI enabled smart camera w/ torch enabled by the Thundercom Kit which spots, prevents, and reports environmental polluters.

AdvancedProtipOver 3 days95
AI enV-Protector: Spots, Prevents, and Reports Polluters.

Things used in this project

Story

Read more

Schematics

Motor Control Board

L298 Motor Control Board

Code

DC Motor Control For Panning Function

Arduino
This is an arduino motor code snippet for controlling the panning motor using a DC geared motor in tandem with a L298 controller board and a arduino uno board.
// demonstration code for the dc motor control for panning the Thundercomm AI Kit
    
	// pin definitions for arduino nano pin assignments
 
    #define enA 9
    #define in1 6
    #define in2 7
	  #define pwm 120

    int direction = 0;
    int pressed = false;
    void setup() {
      pinMode(enA, OUTPUT); // turn mosfet output stage on pin 
      pinMode(in1, OUTPUT); // upper mosfet stage pin
      pinMode(in2, OUTPUT); // lower mosfet stage pin

      // Set initial rotation direction
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
    }
    void loop() {
  
  // Coutner for loop  
	int i;
    
      // demonstrate rotation to the right
      for (i=0; i< 22; i++){ // exactly 180 degree rotation is 23 with a delay of 1 second. 
        analogWrite(enA, pwm); // Send PWM signal to L298N Enable pin      
        digitalWrite(in1, LOW); // Turn upper mosfet off
        digitalWrite(in2, HIGH); // Turn lower mosfet on
        direction = 0;
        delay(20);				// Delay for 20 - 20ms
        analogWrite(enA, LOW);  // Turn off the pwm
        delay (3000); 			// Delay for 3000 - 3sec
      }
    
	   // demonstrate rotation to the left
       for (i=0; i< 22; i++){ 
        analogWrite(enA, pwm);	// Send PWM signal to L298N Enable pin      
        digitalWrite(in1, HIGH);// Turn upper mosfet on		
        digitalWrite(in2, LOW); // Turn lower mosfet off
        direction = 1;
        delay(20);			    // Delay for 20ms
        analogWrite(enA, LOW);  // Turn off the PWM
        delay (3000); 			// Delay for 3 second
      }
        }

LED Control Code Using the L298 Board

Arduino
Arduino control code using the L298 motor control board and the arduino uno board. Simple but impactful example on driving a LED torch using the second half of the L298 motor control.
// demonstration code for the LED torch control on the Thundercom AI Kit
    
	  // pin definitions for arduino nano pin assignments
    #define enA 9
    #define in1 6
    #define in2 7
    #define in3 10
    #define enB 11
    #define low 2
    #define high 10 
    
  	// initial brightness level
    int bright = 2;
    
    void setup() {
      pinMode(enB, OUTPUT);
      pinMode(in3, OUTPUT);

      // set pwm pin for the led connection
      digitalWrite(in3, HIGH);
    }
    void loop() {
      
        analogWrite(enB, bright);	// send PWM signal to L298N Enable pin      
        digitalWrite(in3, HIGH);	// turn the led on
        delay(3000);				      // delay for 3 seconds

        if (bright== low){			  // if previous setting was low
           bright = high;			    // then turn it to high
         }
         else {

          bright = low;				    // otherwise turn it to the low setting
         }        
  }

Credits

wally

wally

1 project • 0 followers

Comments