Specifications
- Switched current: 0.7 A.
- Switching capacity: 10 W.
- Temperature range: −40 to +125 °C.
Overview
The magnetic-field sensor activates when a magnet is brought near it. The activation distance depends on the magnet’s strength and is usually no more than a few centimeters.
Using the sensor
Connecting
The sensor uses a standard 3-pin connector and plugs into any IN port on the Trackduino controller.
Programming
The Magnetic field block is in the Sensors block group.
| Block and generated function | Description |
|---|---|
![]() bool digitalRead(int port) | Returns TRUE when the sensor is activated.int port: port connected to the sensor. |
Example project
Magnetic key
Generated code:
void setup()
{
pinMode( IN1 , INPUT);
}
void loop()
{
if (digitalRead(IN1))
{
startMotor(1, 80);
startMotor(2, 80);
}
else
{
stopMotor(1);
stopMotor(2);
}
}

