As we move forward, we could really benefit from a better text editor than IDLE to edit our Python Code. In today’s lesson I show you how to download and install Pyscripter, which will make your python coding much easier. I suggest you follow these instructions and move to Pyscripter, as I will be using it for future lessons.
Category Archives: Arduino
Arduino Tutorial 38: Using a Tilt Switch Cut Off With a DC Motor
In this lesson we explore how to add a tilt cutoff to our DC motor project. In many cases, you may want to automatically turn your motors off in the case where your project or robot tips over. The tilt switch is a simple way to do this. The video below takes you through the process step-by-step.
If you need help hooking the circuit up, the diagram below shows you a schematic of what we are working with. All these components are part of our ELEGOO Super Starter Kit.
In addition, you will need to add the tilt switch, as shown in the video.
Below is the code we used, with the tilt switch connected to pin 2 on the arduino.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | int speedPin=5; int dir1=4; int dir2=3; int mSpeed=255; int tiltPin=2; int tiltVal; void setup() { // put your setup code here, to run once: pinMode(speedPin,OUTPUT); pinMode(dir1,OUTPUT); pinMode(dir2,OUTPUT); pinMode(tiltPin,INPUT); digitalWrite(tiltPin,HIGH); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(dir1,LOW); digitalWrite(dir2,HIGH); tiltVal=digitalRead(tiltPin); Serial.println(tiltVal); if (tiltVal==0){ analogWrite(speedPin,mSpeed); } if (tiltVal==1){ analogWrite(speedPin,0); } } |
9-Axis IMU LESSON 15: Dynamic 3D Visualizations in Vpython
In this lesson we show you how to animate, or bring your Vpython objects to life by changing their parameters dynamically. In later lessons we will do this via life readings from sensors.
Arduino Tutorial 37: Understanding How to Control DC Motors in Projects
In this lesson we learn the ins and outs of controlling a DC Motor from an Arduino. A key aspect of this is to understand you must not connect a motor directly to an arduino. You need to either build a suitable transistor and diode circuit, or you need to utilize a motor controller, such as the L293D motor control chip.
The video below explains how to hook things up and how the code works. You must always be mindful that you are using a motor with current requirements that are consistent with the motor controller and power supply you are working with. Failure to do so could result in damage to components or injury.
The circuit used in this video tutorial is shown below:
It is a good practice to have all grounds connected in a circuit, so I would connect an arduino ground to the ground rail of the breadboard. The components used in this project are from the Elegoo starter kit, which you can pick up HERE. The code is described in the video, but if you need help, this is the code we used in the lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | int speedPin=5; int dir1=4; int dir2=3; int mSpeed=90; void setup() { // put your setup code here, to run once: pinMode(speedPin,OUTPUT); pinMode(dir1,OUTPUT); pinMode(dir2,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(dir1,LOW); digitalWrite(dir2,HIGH); analogWrite(speedPin,255); delay(25); analogWrite(speedPin,mSpeed); delay(5000); } |
9-Axis IMU LESSON 14: Introduction to Animating Objects in Vpython
In this lesson we need to become more comfortable working with objects in Vpython. WE will show how to create an animated thermometer using the simple commands we have already learned.